<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title></title>
<link rel="stylesheet" href="css/pintuer.css">
<link rel="stylesheet" href="css/admin.css">
<script src="js/jquery-2.1.0.js"></script>
<script src="js/pintuer.js"></script>
</head>
<body>
<div class="panel admin-panel">
  <div class="panel-head"><strong class="icon-reorder"> 课程列表</strong></div>
  <div class="padding border-bottom">
    <button type="button" class="button border-yellow" onclick="window.location.href='#add'"><span class="icon-plus-square-o"></span> 课程管理</button>
  </div>
  
  <table id="coursetable"  class="table table-hover text-center">
  </table>
  
</div>
<script type="text/javascript">
function del(id,mid){
	if(confirm("您确定要删除吗?")){			
		
	}
}
</script>
<div class="panel admin-panel margin-top">
  <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>添加课程</strong></div>
  <div class="body-content">
    <form  class="form-x" >
     
      <div class="form-group">
        <div class="label">
          <label>课程名称：</label>
        </div>
        <div class="field">
          <input id="icoursename" type="text" class="input w50" name="title" />
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>课程简介：</label>
        </div>
        <div class="field">
          <textarea  id="icourseintro" type="text" class="input w50" name="tits" style="height:150px;" placeholder="请描述该课程"></textarea>
          <div class="tips">分条描述请转行</div>
        </div>
      </div>
      
      
      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <button onclick="addcourse()"  class="button bg-main icon-check-square-o"  style="text-align: center;"> 提交</button>
        </div>
      </div>
    </form>
  </div>
</div>
</body>


     <script type="text/javascript">
       /*上传的数据*/
     	 var val;
		   $(window).load(function() {
			 val = {
			 };
			 $("#coursetable").empty();
       net();
			 });
			 
			 function net()
		 {
		 	
		 		$("#coursetable").append('<tr><th width="5%">课程编号</th><th width="15%">课程名称</th><th width="10%">课程简介</th><th width="10%">操作</th></tr>');
		 	
      var url = 'http://119.3.13.186:8080/ZDEduBooking/servlet/QueryCourseServlet';
      $.ajax({
        url: url,
      	type: 'POST',
        data: {
						DATA: JSON.stringify(val)
			  },
        dataType: 'json',
        crossDomain: true,
        success: function(data) {
          for(var i = 0; i < data.clist.length; i++) {
							var courseid = data.clist[i].courseid;
							var coursename= data.clist[i].coursename;
							var courseintro= data.clist[i].courseintro;
   
							$("#coursetable").append('<tr><td>'+courseid+'</td><td>'+coursename+'</td><td>'+courseintro+'</td><td><div class="button-group"> <a class="button border-main" href="cateedit.html?myvalue='+courseid+'"><span class="icon-edit"></span> 修改</a> <a class="button border-red" href="javascript:void(0)" onclick="deletecourse('+courseid+')"><span class="icon-trash-o"></span> 删除</a> </div></td></tr>');
						}
        },
						error: function(xhr, type, errorThrown) {
							alert("服务器异常，请稍后再试:" + type);
						}
      });
		}
		 
		  function addcourse()
		 {
		 	  val = {
		 	  "coursename": $('#icoursename').val(),
				"courseintro": $('#icourseintro').val(),
			  };
		 	
      var url = 'http://119.3.13.186:8080/ZDEduBooking/servlet/AddCourseServlet';
      $.ajax( {
      	url: url,
      	type: 'POST',
        data: {
						DATA: JSON.stringify(val)
			  },
        dataType: 'json',
        crossDomain: true,
        success: function(data) {
                if(data.result=='0')
               {
               	   alert("添加课程成功");
               	   history.back(-1);
               }
               else{
               	   alert("添加课程失败");
               }
        },
						error: function(xhr, type, errorThrown) {
							   alert("服务器异常，请稍后再试:" + type);
						}
					});
		}
		 
		 function deletecourse(did)
		 {
		 	  if(did==14){
		 	  	alert('不允许删除该课!');
		 	  }
		 	  else{
		 	  	 var msg=confirm("确认删除该课程吗？");
            	if(msg==true)
            	{
            		 val = {
		 	  "courseid": did,
			  };
		 	
      var url = 'http://119.3.13.186:8080/ZDEduBooking/servlet/DeleteCourseServlet';
      $.ajax( {
      	url: url,
      	type: 'POST',
        data: {
						DATA: JSON.stringify(val)
			  },
        dataType: 'json',
        crossDomain: true,
        success: function(data) {
                if(data.result=='0')
               {
               	   alert("删除课程成功");
               	   window.location.reload(true)
               }
               else{
               	   alert("删除课程失败");
               }
        },
						error: function(xhr, type, errorThrown) {
							   alert("服务器异常，请稍后再试:" + type);
						}
					});
            	}
		 	
		 	  }
		        
		 	 
		}
		 
     </script>
</html>